package com.wangsong.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wangsong.system.dao.ProductMapper;
import com.wangsong.system.model.Product;
import com.wangsong.system.service.ProductService;
import com.wangsong.system.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcuctServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public ProductVO selectByPrimaryKey(Long id) {
        return  productMapper.selectByPrimaryKey(id);

    }

    @Override
    public Boolean insertProduct(Product product) {
        if(productMapper.insertProduct(product)!=1){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    @Override
    public Boolean updateProduct(Product product) {
        if(product.getId()==null){
            throw new RuntimeException("传入的参数错误");
        }
        if(productMapper.updateProduct(product)!=1){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    @Override
    public Boolean deleteById(Long[] ids) {
        if(productMapper.deleteById(ids)<=0){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    @Override
    public PageInfo<ProductVO> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ProductVO> list=productMapper.selectAll();
        PageInfo<ProductVO> pageInfo= new PageInfo<>(list);
        return null;
    }


}
